function test(params) {
    const size = 5;

function toggle(state, row, col) {
    const directions = [
        [0, 0], // center
        [-1, 0], // top
        [1, 0], // bottom
        [0, -1], // left
        [0, 1] // right
    ];

    directions.forEach(([dx, dy]) => {
        const newRow = row + dx;
        const newCol = col + dy;
        if (newRow >= 0 && newRow < size && newCol >= 0 && newCol < size) {
            state[newRow][newCol] = !state[newRow][newCol];
        }
    });
}

function isAllOff(state) {
    return state.flat().every(cell => !cell);
}

function backtrack(state, row, col, steps) {
    if (isAllOff(state)) {
        return steps; // 返回点击步骤
    }

    if (col === size) {
        col = 0;
        row++;
    }

    if (row === size) {
        return null; // 到达最后一行仍未解决
    }

    // 不点击当前灯
    const resultWithoutClick = backtrack(state, row, col + 1, steps);
    if (resultWithoutClick) return resultWithoutClick;

    // 点击当前灯
    const newState = state.map(row => row.slice());
    toggle(newState, row, col);
    const resultWithClick = backtrack(newState, row, col + 1, [...steps, [row, col]]);
    return resultWithClick;
}

function solveLights(initialState) {
    const result = backtrack(initialState, 0, 0, []);
    return result || "无解";
}

// 示例使用
let initialState = [
    [true, false, true, false, true],
    [false, true, false, true, false],
    [true, false, true, false, true],
    [false, true, false, true, false],
    [true, false, true, false, true],
];

const solution = solveLights(initialState);
console.log("解决方案步骤：", solution);
}
test()